package com.rainng.coursesystem.controller;

import com.rainng.coursesystem.model.vo.response.ResultVO;
import okhttp3.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

@RequestMapping("/test")
@RestController
public class testController {

    @GetMapping("/data")
    public String getAllowStudentSelect(@RequestParam String session,@RequestParam String productModel) throws IOException {

//        OkHttpClient client = new OkHttpClient().newBuilder()
//                .build();
//        MediaType mediaType = MediaType.parse("application/json;charset=UTF-8");
//        RequestBody body = RequestBody.create(mediaType, "{\"applyId\":\"d3fa0e4ee3f54f21a620ba3a69822769\",\"rowType\":4,\"isQueryHistoryAnnouncing\":\"0\",\"totalSize\":0,\"currentPage\":1,\"pageSize\":10,\"position\":\"right\",\"pageSizes\":[5,10,20],\"layout\":\"sizes,total, prev, pager, next,jumper\"}");
//        Request request = new Request.Builder()
//                .url("https://clcpzr-inspection.miit.gov.cn/inspection-center/ProductCtrl/queryPage")
//                .method("POST", body)
//                .addHeader("Accept", "application/json, text/plain, */*")
//                .addHeader("Accept-Language", "zh-CN,zh;q=0.9")
//                .addHeader("Authorization", "")
//                .addHeader("Connection", "keep-alive")
//                .addHeader("Content-Type", "application/json;charset=UTF-8")
//                .addHeader("Cookie", session)
//                .addHeader("Origin", "https://clcpzr-inspection.miit.gov.cn")
//                .addHeader("Referer", "https://clcpzr-inspection.miit.gov.cn/inspection-web/addNewCar?readOnly=1&applyId=d3fa0e4ee3f54f21a620ba3a69822769&applyCode=3&applyName=N1%E7%B1%BB%EF%BC%8C%20%E6%A0%B9%E6%8D%AE%E6%95%B4%E8%BD%A6%E6%94%B9%E8%A3%85&applyMethod=zc&vehicleCode=04&vehicleName=%E4%B8%93%E7%94%A8%E8%BD%A6&applyOperationCode=01&isXNY=1&isMeetingDualSlope=1&isStatisticsSt=0&shapingInstitutionCode=QV&inspectionInstitutionCode=QV&productStandardName=%E6%97%85%E5%B1%85%E8%BD%A6&needConfigDualSlope=1&modelName=xcp&typeName=newProduct&applyType=qc&applyUserId=b0324becd202457384c168006a8de20f")
//                .addHeader("Sec-Fetch-Dest", "empty")
//                .addHeader("Sec-Fetch-Mode", "cors")
//                .addHeader("Sec-Fetch-Site", "same-origin")
//                .addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36")
//                .addHeader("sec-ch-ua", "\"Chromium\";v=\"124\", \"Google Chrome\";v=\"124\", \"Not-A.Brand\";v=\"99\"")
//                .addHeader("sec-ch-ua-mobile", "?0")
//                .addHeader("sec-ch-ua-platform", "\"Windows\"")
//                .build();
//        Response response = client.newCall(request).execute();
//        OkHttpClient client = new OkHttpClient().newBuilder()
//                .build();
//        MediaType mediaType = MediaType.parse("application/json;charset=UTF-8");
//        RequestBody body = RequestBody.create(mediaType, "{\"inspectionCode\":\"QV\",\"applyCode\":1,\"enterpriseName\":null,\"productModel\":\"CLW5160ZXLCDP\",\"announcementBatch\":null,\"currentPage\":1,\"pageSize\":10,\"position\":\"center\",\"layout\":\"total, sizes, prev, pager, next, jumper\",\"pageSizes\":[10,30,50,100,200],\"totalSize\":12681}");
//        Request request = new Request.Builder()
//                .url("https://clcpzr-inspection.miit.gov.cn/inspection-center/ProductCtrl/queryProductInfoList")
//                .method("POST", body)
//                .addHeader("Accept", "application/json, text/plain, */*")
//                .addHeader("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8,zh-TW;q=0.7,en-US;q=0.6,ja;q=0.5")
//                .addHeader("Authorization", "")
//                .addHeader("Connection", "keep-alive")
//                .addHeader("Content-Type", "application/json;charset=UTF-8")
//                .addHeader("Cookie", "SESSION=YTNmYjkxNTUtZWFkYy00YmRiLWJlYTAtNzI4ZDJmMjkzZmE1; __jsluid_s=7d22e2083ba6a5f0ac5face418a0a672; route=1718093656.657.111041.148487; cssSessionId=a2cd474dc51b4376866f111a471295c0; SESSION=ZWUzMzYwMTgtY2QwMS00ZmUxLTk4YmQtMGNkNTllOTliNzJm; __jsluid_h=8721cc6938cfdedfe2581d67a39006ff; __jsluid_s=a19c2c5a960bfba97fef67280088f008; route=1718257601.898.113740.519921")
//                .addHeader("Origin", "https://clcpzr-inspection.miit.gov.cn")
//                .addHeader("Referer", "https://clcpzr-inspection.miit.gov.cn/inspection-web/productInformationquery")
//                .addHeader("Sec-Fetch-Dest", "empty")
//                .addHeader("Sec-Fetch-Mode", "cors")
//                .addHeader("Sec-Fetch-Site", "same-origin")
//                .addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36")
//                .addHeader("sec-ch-ua", "\"Google Chrome\";v=\"125\", \"Chromium\";v=\"125\", \"Not.A/Brand\";v=\"24\"")
//                .addHeader("sec-ch-ua-mobile", "?0")
//                .addHeader("sec-ch-ua-platform", "\"Windows\"")
//                .build();
//        Response response = client.newCall(request).execute();
//        String VV=response.body().string();



        OkHttpClient client = new OkHttpClient().newBuilder()
                .build();
        MediaType mediaType = MediaType.parse("application/json;charset=UTF-8");
        RequestBody body = RequestBody.create(mediaType, "{\"inspectionCode\":\"QV\",\"applyCode\":1,\"enterpriseName\":null,\"productModel\":\"CLW5160ZXLCDP\",\"announcementBatch\":null,\"currentPage\":1,\"pageSize\":10,\"position\":\"center\",\"layout\":\"total, sizes, prev, pager, next, jumper\",\"pageSizes\":[10,30,50,100,200],\"totalSize\":12681}");
        Request request = new Request.Builder()
                .url("https://clcpzr-inspection.miit.gov.cn/inspection-center/ProductCtrl/queryProductInfoList")
                .method("POST", body)
                .addHeader("Accept", "application/json, text/plain, */*")
                .addHeader("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8,zh-TW;q=0.7,en-US;q=0.6,ja;q=0.5")
                .addHeader("Authorization", "")
                .addHeader("Connection", "keep-alive")
                .addHeader("Content-Type", "application/json;charset=UTF-8")
                .addHeader("Cookie", "SESSION=YTNmYjkxNTUtZWFkYy00YmRiLWJlYTAtNzI4ZDJmMjkzZmE1; __jsluid_s=7d22e2083ba6a5f0ac5face418a0a672; route=1718093656.657.111041.148487; cssSessionId=a2cd474dc51b4376866f111a471295c0; SESSION=ZWUzMzYwMTgtY2QwMS00ZmUxLTk4YmQtMGNkNTllOTliNzJm; __jsluid_h=8721cc6938cfdedfe2581d67a39006ff; __jsluid_s=a19c2c5a960bfba97fef67280088f008; route=1718257601.898.113740.519921")
                .addHeader("Origin", "https://clcpzr-inspection.miit.gov.cn")
                .addHeader("Referer", "https://clcpzr-inspection.miit.gov.cn/inspection-web/productInformationquery")
                .addHeader("Sec-Fetch-Dest", "empty")
                .addHeader("Sec-Fetch-Mode", "cors")
                .addHeader("Sec-Fetch-Site", "same-origin")
                .addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36")
                .addHeader("sec-ch-ua", "\"Google Chrome\";v=\"125\", \"Chromium\";v=\"125\", \"Not.A/Brand\";v=\"24\"")
                .addHeader("sec-ch-ua-mobile", "?0")
                .addHeader("sec-ch-ua-platform", "\"Windows\"")
                .build();
        Response response = client.newCall(request).execute();
        String VV=response.body().string();

//        OkHttpClient client = new OkHttpClient().newBuilder()
//                .build();
//        MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded; charset=UTF-8");
//        RequestBody body = RequestBody.create(mediaType, "password=d892fc2f68aec09d42e009c36d0937eb&logintype=sendMessage&mobile=&flag=&toUrl=http%253A%252F%252Fclcpzr-inspection.miit.gov.cn%252Finspection-center%252FLoginCtrl%252Flogin&username=wangxiangyu%40&getyznum=&yznum=529129");
//        Request request = new Request.Builder()
//                .url("https://ucenter.miit.gov.cn/login.action")
//                .method("POST", body)
//                .addHeader("Accept", "application/json, text/javascript, */*; q=0.01")
//                .addHeader("Accept-Language", "zh-CN,zh;q=0.9")
//                .addHeader("Connection", "keep-alive")
//                .addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
//                .addHeader("Origin", "https://ucenter.miit.gov.cn")
//                .addHeader("Referer", "https://ucenter.miit.gov.cn/login.jsp?toUrl=http%3A%2F%2Fclcpzr-inspection.miit.gov.cn%2Finspection-center%2FLoginCtrl%2Flogin")
//                .addHeader("Sec-Fetch-Dest", "empty")
//                .addHeader("Sec-Fetch-Mode", "cors")
//                .addHeader("Sec-Fetch-Site", "same-origin")
//                .addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36")
//                .addHeader("X-Requested-With", "XMLHttpRequest")
//                .addHeader("sec-ch-ua", "\"Google Chrome\";v=\"125\", \"Chromium\";v=\"125\", \"Not.A/Brand\";v=\"24\"")
//                .addHeader("sec-ch-ua-mobile", "?0")
//                .addHeader("sec-ch-ua-platform", "\"Windows\"")
//                .addHeader("Cookie", "jsessionid=rBQPQhroZmKyFRUswhUUBk8EuvFDdIS3cNYA; wzws_sessionid=oGZhZ1KAMjIyLjk1LjEwOS4xODSBYzkyYmFhgjI1ZDIyMw==")
//                .build();
//        Response response = client.newCall(request).execute();
//
//
//        List<Cookie> cookies = Cookie.parseAll(request.url(), response.headers());
//        for (Cookie cookie : cookies) {
//            String C=cookie.name();
//            System.out.println(cookie.name());
//            // 处理Cookie
//            // 可以将Cookie保存起来，用于后续的请求
//        }
       return VV;
    }
}
